/*
 * @Author: zhangjingyu
 * @Date: 2020-10-22 19:29:56
 * @LastEditors: zhangjingyu
 * @LastEditTime: 2020-12-29 12:57:50
 * @FilePath: \vprisk10.14\src\store\user.js
 * @Description: 
 */

import Cookie from 'js-cookie'
export default {
  state: {
    token: '',
    key: "40ca11f573cce61cc28e19998d5bb1c8",// 用于密码传输的key
    userInfo:null,//當前用戶信息
    message: {
      count:0
    },
  },
  mutations: {
    setCount(state, val) {
      state.message.count = val
    },
    setToken(state, val) {
      state.token = val
      sessionStorage.setItem("loginToken",val);
    }, 
    setUserInfo(state,val) {
      state.userInfo = val;
    },
    clearToken(state) {
      state.token = ''
      sessionStorage.removeItem('loginToken');
    },
    // 防止刷新后丢失token，设置获取token的方法
    getToken(state) {
      // state.token = Cookie.get('token')
      sessionStorage.getItem("loginToken");
    },
  },
  actions: {
    logOut(connext){
       // 置空token
      connext.commit("clearToken");
      // 清除菜单
      connext.commit("clearMenu");
      sessionStorage.removeItem("moduleShow");
      sessionStorage.removeItem("tennatId");
      sessionStorage.removeItem("tennatName");
      // 刷新浏览器
      location.reload();
    }
  }
}
